import hashlib

def restore_model(backup_path, expected_hash):
    """
    恢复模型
    :param backup_path: 备份路径
    :param expected_hash: 预期的哈希值
    :return: 恢复的模型
    """
    with open(backup_path, "rb") as f:
        model = f.read()
    model_hash = hashlib.sha256(model).hexdigest()
    if model_hash != expected_hash:
        raise ValueError("Invalid backup")
    return model

# 示例
backup_path = "backup_model.bin"
expected_hash = "your_expected_hash"
restored_model = restore_model(backup_path, expected_hash)
print(f"Model restored: {restored_model}")